package com.linq.cool.beauty.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.linq.cool.beauty.domain.BeautyOrderHistory;
import com.linq.cool.beauty.service.BeautyOrderHistoryService;
import com.linq.cool.common.core.domain.BaseController;
import com.linq.cool.common.core.domain.Result;
import com.linq.cool.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: yqlin
 * @Date: 2021/2/15 04:38
 * @Description:
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("orderHistory")
public class BeautyOrderHistoryController extends BaseController {
    @Autowired
    private BeautyOrderHistoryService orderHistoryService;

    /**
     * 查询客户订单的操作进度
     *
     * @param orderId
     *
     * @return
     */
    @GetMapping("getMemberOrderProgress/{orderId}")
    public Result<?> getMemberOrderProgress(@PathVariable("orderId") Long orderId) {
        List<BeautyOrderHistory> list = orderHistoryService.list(new LambdaQueryWrapper<BeautyOrderHistory>()
                                                                         .eq(BeautyOrderHistory::getOrderId, orderId)
                                                                         .eq(BeautyOrderHistory::getMemberId, SecurityUtils.getUserId())
                                                                         .orderByAsc(BeautyOrderHistory::getGmtCreate)
        );
        if (CollectionUtils.isEmpty(list)) {
            list = new ArrayList<>();
        }
        return Result.ok(list);
    }
}
